<?php
/**
 * PartCategoryController.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-05-12 16:24:40
 * @modified    2023-05-12 16:24:40
 *
 */

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Repositories\PartCategoryRepo;

class PartCategoryController extends BaseModuleController
{
    public function params()
    {
        try {
            $params = PartCategoryRepo::params();
            return message('获取成功', true, $params);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function index(Request $request)
    {
        try {
            $pcs = PartCategoryRepo::getList();
            return list_message('获取成功', true, $pcs);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function show(Request $request, $id)
    {
        try {
            $partCategory = PartCategoryRepo::fetch($id);
            return message('获取成功', true, $partCategory);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function destroy(Request $request, $id)
    {
        try {
            PartCategoryRepo::destroy($id);
            return message('删除成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function store(Request $request)
    {
        try {
            $partCategory = PartCategoryRepo::store(0);
            return message('保存成功', true, $partCategory);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function update(Request $request, $id)
    {
        try {
            $partCategory = PartCategoryRepo::store($id);
            return message('保存成功', true, $partCategory);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function active(Request $request, $id)
    {
        try {
            $partCategory = PartCategoryRepo::active($id);
            return message('开启成功', true, $partCategory);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function inactive(Request $request, $id)
    {
        try {
            $partCategory = PartCategoryRepo::inactive($id);
            return message('关闭成功', true, $partCategory);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }
}